package com.ktjiaoyu.server.listener;

import com.ktjiaoyu.server.pojo.Admin;
import com.ktjiaoyu.server.service.IAdminService;
import com.ktjiaoyu.server.utils.SpringContextUtil;
import org.activiti.engine.TaskService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.security.core.context.SecurityContextHolder;

public class TaskListenerImpl implements TaskListener {


    @Override
    public void notify(DelegateTask delegateTask) {
        //1.获取当前登录用户
        Admin admin =(Admin) SecurityContextHolder.getContext()
                .getAuthentication().getPrincipal();

        //2.获取当前登录用户的直接领导
        Integer mgr = admin.getMgr();
        IAdminService adminService =
                SpringContextUtil.getBean(IAdminService.class);
        Admin mgrAdmin = adminService.getById(mgr);

        //3.设置经办人
        TaskService taskService =
                SpringContextUtil.getBean(TaskService.class);
        taskService.setAssignee(delegateTask.getId(),mgrAdmin.getName());
    }
}
